package grex.genes;

import grex.Options;
import grex.Prediction;
import grex.PredictionContainer;

import java.text.NumberFormat;

public class SmallConstant extends Gene {

    private double value = 0;

    public SmallConstant() {
        super(0);
        value = (Options.rnd.nextDouble() * 2-1);
    }

    public synchronized void execute(Gene parent, PredictionContainer data, int mode) throws GeneException {
        this.parent = parent;
        for (Prediction c : data.values()) {
            c.setPrediction(value);
        }
    }

    public String toString() {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);
        return "" + nf.format(value);
    }

    public Object clone() {
        SmallConstant newConVal = new SmallConstant();
        newConVal.setOptions(ops);
        newConVal.setEnvironment(environment);
        newConVal.value = value;
        newConVal.setParent(parent);
        return newConVal;
    }
}
